/* 终审 */
<template>
  <div>
    <Card :bordered="false">
      <p slot="title">终审</p>
      <MyTrialTab :info="info" />
      <table style="margin-bottom: 20px" width='100%' border="1" cellspacing="0" cellpadding="0">
        <tr>
          <th colspan="6">
            初审修改
          </th>
        </tr>
        <tr>
          <td width="16.66%">
            修改人员
          </td>
          <td width="16.66%">
            <div class="ivu-table-cell"><template>
                <Select v-model="info.cModifier" @on-change="chengeXgry" :label-in-value="true">
                  <Option v-for="(item,index) in xzRy" :value="item.value" :label="item.label" :key="item.index">{{
                    item.label }}</Option>
                  <!-- <Option v-for="item in xzRy" :value="item.Staff_name" :key="item.staffs_name">{{ item.Staff_name }}</Option> -->
                </Select>
              </template></div>
          </td>
          <td width="16.66%">
            初审时间
          </td>
          <td width="16.66%">
          </td>
          <td width="16.66%">
            修改完成时间
          </td>
          <td width="16.66%">
          </td>
        </tr>
        <tr>
          <td colspan="6">
            <div style="width:99%;margin:auto;height:100%;">
              <Table border ref="selection" style="border: none" :columns="chushenColumns" :data="info.Chushen"
                :loading="chushenLoading"></Table>
            </div>
          </td>
        </tr>
      </table>
      <table style="margin-bottom:20px" cellspacing="0" cellpadding="0" border="1" width="100%">
        <tr>
          <th colspan="6">复审修改</th>
        </tr>
        <tr>
          <td width="16.66%">
            修改人员
          </td>
          <td width="16.66%">
          </td>
          <td width="16.66%">
            初审时间
          </td>
          <td width="16.66%">
          </td>
          <td width="16.66%">
            修改完成时间
          </td>
          <td width="16.66%">
          </td>
        </tr>
        <tr>
          <td colspan="6" style="padding:0 5px;">
            <div style="width:99%;margin:auto;height:100%;">
              <Table border ref="selection" style="border: none" :columns="fushenColumns" :data="info.Fushen" :loading="fushenLoading"></Table>
            </div>
          </td>
        </tr>
      </table>
      <table style="margin-bottom:20px" cellspacing="0" cellpadding="0" border="1" width="100%">
        <tr>
          <th colspan="4">终审单</th>
        </tr>
        <tr>
          <td width="25%">终审工程师</td>
          <td width="25%">{{info.zaudit}}</td>
          <td width="25%">终审时间</td>
          <td width="25%">
            {{this.$moment().format('YYYY-MM-DD')}}
          </td>
        </tr>
        <tr>
          <td colspan="4" style="padding:0 5px;">
            <div style="width:99%;margin:auto;height:100%;">
              <Table border ref="selection" style="border: none" :columns="zhongshenColumns" :data="info.Zhongshen"
                :loading="zhongshenLoading" @on-row-click="getIndex"></Table>
              <Row>
                <Col span="24" style="text-align: center;padding:10px">
                <Button type="primary" @click="inputAdd('Zhongshen')">添加</Button>
                <Button type="error" @click="inputRemove('Zhongshen')">删除</Button>
                </Col>
              </Row>
            </div>
          </td>
        </tr>
        <tr>
          <td>
            报告（正文、附图、附件、附表）
          </td>
          <td colspan="3">
            <Upload action="//jsonplaceholder.typicode.com/posts/">
              <Button>上传</Button>
            </Upload>
          </td>
        </tr>
      </table>
      <Row style="margin-top: 10px">
        <Col span="24" style="text-align:right;">
        <Button type="primary" @click="submit">发送意见</Button>
        </Col>
      </Row>
    </Card>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        xzRy: [],
        loading: true,
        chushenLoading: true,
        fushenLoading: true,
        zhongshenLoading: true,
        query: [],
        info: [],
        chushenColumns: [{
            align: 'center',
            type: 'selection',
            width: 60
          },
          {
            align: 'center',
            title: '序号',
            key: 'num',
            width: 80
          },
          {
            align: 'center',
            title: '初审意见',
            key: 'Audit_opinion'
          },
          {
            align: 'center',
            title: '修改说明',
            key: 'Revise_explain'
          },
        ],
        fushenColumns: [{
            align: 'center',
            type: 'selection',
            width: 60
          },
          {
            align: 'center',
            title: '序号',
            key: 'num',
            width: 80
          },
          {
            align: 'center',
            title: '复审意见',
            key: 'Audit_opinion'
          },
          {
            align: 'center',
            title: '修改说明',
            key: 'Revise_explain'
          },
        ],
        zhongshenColumns: [{
            align: 'center',
            title: '序号',
            type: 'index',
            width: 80
          },
          {
            align: 'center',
            title: '终审意见',
            key: 'Audit_opinion',
            render: (h, {
              row,
              index
            }) => {
              return h('Input', {
                props: {
                  type: 'text',
                  value: row.Audit_opinion
                },
                on: {
                  'on-blur': (val) => {
                    this.info.Zhongshen[index].Audit_opinion = val.target.value
                  }
                }
              })
            }
          },
        ],
      }
    },
    mounted() {
      let query = this.$route.query
      this.query = query
      this.findByProject(query.Project_id, query.Atype)
    },
    methods: {
      chengeXgry(value) {
        console.log(value)
        axios.get('/assignjobs/setModifier', {
          params: {
            Project_id: this.$route.query.Project_id,
            Atype: "初审",
            Modifier: value.value
          }
        }).then(res => {
          console.log(res)
          let title = res._MESSAGE
          if (res._STATUS == 1) {
            this.$Modal.success({
              title
            })
          } else {
            this.$Modal.error({
              title
            })
          }
        })
      },
      inputAdd(type) {
        this.info[type].push({})
      },
      inputRemove(type) {
        this.info[type].splice(this.allIndex, 1);
        console.log(this.info[type] + ' 被删除了')
      },
      getIndex(data, index, event) {
        this.allIndex = index;
      },
      findByProject(Project_id, Atype) {
        axios.get('/audit/findByProject', {
          params: {
            Atype,
            Project_id
          }
        }).then(res => {
          this.info = res
          this.chushenLoading = false
          this.fushenLoading = false
          this.zhongshenLoading = false
          console.log(this.info)
          this.getXgry()
        })
      },
      getXgry() {
        axios.get('/audit/findStaff', {
          params: {
            Project_id: this.$route.query.Project_id
          }
        }).then(res => {
          this.xzRy = res.data
        })
      },
      submit() {
        let query = this.query
        let AuditReplyLists = this.info.Zhongshen
        for (let val of AuditReplyLists) {
          val['Audit_id'] = query.id
          val['Audit_time'] = this.$moment().format('YYYY-MM-DD HH:mm:ss')
        }
        if (Object.keys(AuditReplyLists).length <= 0) {
          this.$Modal.error({
            title: '点击添加请输入意见'
          })
        } else {
          axios.get('/audit/isAuditb', {
            params: {
              Project_id: query.Project_id,
              Btype: query.Atype,
              OK: 1
            }
          }).then(res => {
            let title = res._MESSAGE
            if (res._STATUS == 1) {
              this.$Modal.success({
                title: title + ': 请进入正在进行项目人员提交'
              })
              axios.post('/auditreply/saveOrUpdateM', {
                AuditReplyLists,
              }).then(res => {

              }).catch(err => {
                this.$Modal.error({
                  title: '发送失败'
                })
              })
            } else {
              this.$Modal.error({
                title: title + '：等待业务人员提交'
              })
            }
          })
        }
      }
    },
  }
</script>
<style scoped>
</style>